﻿using System;

using Uber.Messages;
using Uber.HabboHotel.Rooms;

namespace Uber.HabboHotel.Navigators
{
    enum PublicImageType
    {
        INTERNAL = 0,
        EXTERNAL = 1
    }

    class PublicItem
    {
        private int BannerId;

        public int Type;

        public string Caption;
        public string Image;
        public PublicImageType ImageType;

        public uint RoomId;

        public int ParentId;

        public int Id
        {
            get
            {
                return BannerId;
            }
        }

        public RoomData RoomData
        {
            get
            {
                if (RoomId == 0)
                {
                    return new RoomData();
                }
                else
                {
                    return UberEnvironment.GetGame().GetRoomManager().GenerateRoomData(RoomId);
                }
            }
        }

        public Boolean Category;
        public Boolean Recommended;

        public PublicItem(int mId, int mType, string mCaption, string mImage, PublicImageType mImageType, uint mRoomId, int mParentId, Boolean mCategory, Boolean mRecommended)
        {
            this.BannerId = mId;
            this.Type = mType;
            this.Caption = mCaption;
            this.Image = mImage;
            this.ImageType = mImageType;
            this.RoomId = mRoomId;
            this.ParentId = mParentId;
            this.Category = mCategory;
            this.Recommended = mRecommended;
        }

        public void Serialize(ServerMessage Message)
        {
            if (!Category)
            {
                Message.AppendInt32(Id);

                Message.AppendStringWithBreak((Type == 1) ? Caption : RoomData.Name);

                Message.AppendStringWithBreak(RoomData.Description);
                Message.AppendInt32(Type);
                Message.AppendStringWithBreak(Caption);
                Message.AppendStringWithBreak((ImageType == PublicImageType.EXTERNAL) ? Image : "");

                Message.AppendInt32(ParentId);
                Message.AppendInt32(RoomData.UsersNow);
                Message.AppendInt32(3);
                Message.AppendStringWithBreak((ImageType == PublicImageType.INTERNAL) ? Image : "");
                Message.AppendUInt(1337);
                Message.AppendBoolean(true);
                Message.AppendStringWithBreak(RoomData.CCTs);
                Message.AppendInt32(RoomData.UsersMax);
                Message.AppendUInt(RoomId);
            }
            else if (Category)
            {
                Message.AppendInt32(Id);
                Message.AppendStringWithBreak(Caption);
                Message.AppendBreak();
                Message.AppendBoolean(true);
                Message.AppendBreak();
                Message.AppendBreak();
                Message.AppendBoolean(false);
                Message.AppendBoolean(false);
                Message.AppendInt32(4);
                Message.AppendBoolean(false);
            }
        }
    }
}
